import http from "~/api/base/http.js";

//用户登录
export const userLogin = (user) => {
    return http.requestPost("/user/login", user);
};

//登录
export const doLogout = () => {
    return http.requestPost('/user/logout');
};

//获取当前登录的用户
export const getLoginUser = () => {
    return http.requestGet("/user/login-user");
};
//获取当前登录的用户
export const getUserList = (page = 1, size = 999, searchObject = null) => {
    let userKey = "";
    let roleId = "";
    let powerId = "";
    let moneyMin = "";
    let moneyMax = "";
    let amountMin = "";
    let amountMax = "";
    if (searchObject != null) {
        userKey = searchObject.userKey === undefined ? "" : searchObject.userKey;
        roleId = searchObject.roleId === undefined ? "" : searchObject.roleId;
        powerId = searchObject.powerId === undefined ? "" : searchObject.powerId;
        moneyMin = searchObject.moneyMin === undefined ? "" : searchObject.moneyMin;
        moneyMax = searchObject.moneyMax === undefined ? "" : searchObject.moneyMax;
        amountMin = searchObject.amountMin === undefined ? "" : searchObject.amountMin;
        amountMax = searchObject.amountMax === undefined ? "" : searchObject.amountMax;
    }

    return http.requestGet("/user/portal/user-list?page=" + page + "&size=" + size + "&userKey=" + userKey + "&roleId=" + roleId
        + "&powerId=" + powerId + "&moneyMin=" + moneyMin + "&moneyMax=" + moneyMax + "&amountMin=" + amountMin + "&amountMax=" + amountMax);
};

//获取用户信息
export const getUserInfo = (id = "") => {
    return http.requestGet("/user/user_info/" + id);
};

//是否需要输入验证码
export const isCaptchaCode = () => {
    return http.requestGet("/user/utils/check/captcha_code");
};

//校验图灵验证码
export const checkCaptchaCode = (captcha_code) => {
    return http.requestGet("/user/utils/check/captcha_code_right/" + captcha_code);
};

//校验邮箱是否注册
export const checkEmailIsExist = (email) => {
    return http.requestGet("/user/utils/check/email/" + email);
};

//校验用户名是否注册
export const checkUserNameIsExist = (userName) => {
    return http.requestGet("/user/utils/check/user_name/" + userName);
};

//修改用户信息
export const userUpdateMsg = (user) => {
    return http.requestPut("/user/update", user);
};

//用户注册
export const userRegister = (user) => {
    return http.requestPost("/user/register", user);
};

//忘记密码或者修改密码验证邮箱码
export const forgetCheckEmailCode = (email, emailCode) => {
    return http.requestGet("/user/utils/check/email_code?email=" + email + "&emailCode=" + emailCode);
};

//修改密码
export const changePassword = (email, emailCode, newPassword) => {
    return http.requestPut("/user/password?email=" + email + "&emailCode=" + emailCode + "&newPassword=" + newPassword);
};

//修改邮箱
export const changeUserEmail = (newEmail, emailCode) => {
    return http.requestPut("/user/update_email?email=" + newEmail + "&emailCode=" + emailCode);
};

//发送邮箱验证码
export const sendEmailCode = (type, email) => {
    return http.requestGet("/user/utils/email?type=" + type + "&email=" + email);
};
//获取用户会员等级
export const getUserRoleList = () => {
    return http.requestGet("/portal/user-role/list");
};

//获取用户权限表
export const getUserPowerList = () => {
    return http.requestGet("/portal/user-power/list");
};

//发送邮件
export const sendEmailToUser = (emailObj) => {
    return http.requestPost("/user/utils/emailToUser", emailObj);
};

//重置用户密码
export const resetPsd = (userId = null, newPassword = null) => {
    return http.requestPut("/user/admin/initPassword", {userId: userId, newPassword: newPassword});
};

//填写邀请码
export const saveInvitationUser = (code) => {
    return http.requestPut("/user/invitation?code=" + code);
};
//充值卡密
export const rechargeCarmineCode = (code) => {
    return http.requestGet("/portal/carmine/" + code);
};
//领取新人奖励
export const receiveNewGift = (addressId) => {
    return http.requestGet("/user/receive-gift/" + addressId);
};
//获取余额排行榜
export const amountRanking = (size = 15) => {
    return http.requestGet("/user/money-ranking/" + size);
};